package com.logistics.map.controller;

import com.logistics.map.entity.model.MapComponentsPager;
import com.logistics.map.entity.model.MapComponentsSave;
import com.logistics.map.service.MapComponentsService;
import com.logistics.utils.aspect.annotation.LoggerListener;
import com.logistics.utils.constants.LoggerMethod;
import com.logistics.utils.exception.MessageException;
import com.logistics.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
@RequestMapping("/lgs/map/components")
public class MapComponentsController {

    @Autowired
    private MapComponentsService mapComponentsService;

    /**
     * 查找站点
     * @return
     * @throws MessageException
     */
    @GetMapping("sites")
    public ResponseEntity sites() throws MessageException {
        return ResponseUtil.success(mapComponentsService.siteRows());
    }

    @GetMapping("getAgvList")
    public ResponseEntity getAgvList() throws MessageException {
        return ResponseUtil.success(mapComponentsService.getAgvList());
    }

    @PostMapping("pager")
    public ResponseEntity pager(@RequestBody MapComponentsPager mapComponentsPager) throws MessageException {
        return ResponseUtil.success(mapComponentsService.pager(mapComponentsPager));
    }

    /**
     * 保存站点信息
     * @param save
     * @return
     * @throws MessageException
     */
    @PutMapping("save")
    @LoggerListener(businessName = "保存站点信息", methodName = LoggerMethod.SAVE)
    public ResponseEntity save(@RequestBody MapComponentsSave save) throws MessageException {
        mapComponentsService.saveStation(save);
        return ResponseUtil.success();
    }

    @PutMapping("saveAgv")
    @LoggerListener(businessName = "保存AGV信息", methodName = LoggerMethod.SAVE)
    public ResponseEntity saveAgv(@RequestBody MapComponentsSave save) throws MessageException {
        mapComponentsService.saveAgv(save);
        return ResponseUtil.success();
    }

    /**
     * 删除站点信息
     * @param ids
     * @return
     * @throws MessageException
     */
    @DeleteMapping("remove/{ids}")
    @LoggerListener(businessName = "删除站点信息", methodName = LoggerMethod.DELETE)
    public ResponseEntity remove(@PathVariable("ids") String ids) throws MessageException {
        mapComponentsService.delete(ids);
        return ResponseUtil.success();
    }

    /**
     * 查询站点详细
     * @param id
     * @return
     * @throws MessageException
     */
    @GetMapping("details/{id}")
    @LoggerListener(businessName = "查询站点详细", methodName = LoggerMethod.SEARCH)
    public ResponseEntity details(@PathVariable("id") String id) throws MessageException {
        return ResponseUtil.success(mapComponentsService.details(id));
    }

    /**
     * 查询站点详细
     * @param id
     * @return
     * @throws MessageException
     */
    @GetMapping("agvDetail/{id}")
    @LoggerListener(businessName = "查询AGV详细", methodName = LoggerMethod.SEARCH)
    public ResponseEntity agvDetail(@PathVariable("id") String id) throws MessageException {
        return ResponseUtil.success(mapComponentsService.agvDetail(id));
    }

    /**
     * 解锁站点
     * @param uuid
     * @return
     */
    @PutMapping("unLockLocation/{uuid}")
    public ResponseEntity unLockLocation(@PathVariable("uuid") String uuid){
        mapComponentsService.unLockLocation(uuid);
        return ResponseUtil.success();
    }
}